import { isHaveButtonPermission } from '@/utils/permission'
import dayjs from 'dayjs'
import noDataPic from '@/assets/images/noData.png'
import { mapGetters } from 'vuex'
const globalMixin = {
  data() {
    return {
      noImgUrl: noDataPic
    }
  },
  computed: {
    ...mapGetters(['employee'])
  },
  methods: {
    // 获取操作人信息
    getOpereationMsg() {
      if (this.employee) {
        const branchVO = this.employee.branchVO
        const userName = this.employee.userName
        return {
          operator: branchVO && branchVO.jobNumber,
          operatorName: userName
        }
      }
      return {}
    },
    rangeTimeFormatter(newVal) {
      let start = null
      let end = null
      if (newVal && newVal[0]) {
        start = dayjs(newVal[0]).format('YYYY-MM-DD')
      }
      if (newVal && newVal[1]) {
        end = dayjs(newVal[1]).format('YYYY-MM-DD')
      }
      return {
        start,
        end
      }
    },
    hasPermission(code) {
      /** 是否有权限 */
      return isHaveButtonPermission(code)
    },
    /**
     * @Description: 展示模态框错误
     * @author tangyuhui
     * @date 2021/5/5 12:19 下午
    */
    showModalError(title, content) {
      this.$Modal.error({
        title: title,
        content: content
      })
    }
  }
}

export default globalMixin
